<html>
<head><title>Get Cost and Weight</title></head>
<link rel="stylesheet" type="text/css" href="style.css" />  
<body>
<h3>Using the substring function</h3>
<form name=form1>
<font size=2>Product:</font>
<select name="product" onChange=getCostWeight()>
<option value="900000x527">CT Scanner</option>
<option value="600000x751">MRI</option>
<option value="350000x499">Nuclear Medicine</option>
<option value="150000x193">X-Ray</option>
<option value="300000x99">Ultrasound</option>
</select>
<input type=text name=itemcost value="">
<input type=text name=itemweight value="">
</form>
</body>
<script language="JavaScript" type="text/javascript">
function getCostWeight() {
var cost = 0;
var weight = 0;
var nbr = 0;
var len = 0;
var prod = form1.product.value;
len=prod.length;
nbr = prod.indexOf("x");
cost = prod.substring(0,nbr); 
weight = prod.substring(nbr+1,len);
form1.itemcost.value = cost;
form1.itemweight.value = weight; }
</script>
</html>

